1 <?php
2 define(
'DB_SERVER', 'localhost');
3 define(
'DB_USER', 'root');
4 define(
'DB_PASSWORD', '');
5 define(
'DB_NAME', 'muaban');
6
7
8 if
(isset($_GET['term'])){
9     $return_arr = array();
10
11     
try {
12         $conn =
new PDO("mysql:host=".DB_SERVER.";port=8889;dbname=".DB_NAME, DB_USER, DB_PASSWORD);
13         $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
14         
15         $stmt = $conn->prepare(
'SELECT user FROM user_shop WHERE user LIKE :term');
16         $stmt->execute(array(
'term' => '%'.$_GET['term'].'%'));
17         
18         
while($row = $stmt->fetch()) {
19             $return_arr[] = $row[
'user'];
20         }
21
22     }
catch(PDOException $e) {
23         echo
'ERROR: ' . $e->getMessage();
24     }
25
26
27     
/* Toss back results as json encoded array. */
28     echo json_encode($return_arr);
29 }
30
31
32 ?>



Full source code website bán hàng thương mại điện tử gần giống shopee 468.956 lượt xem

Gõ tìm kiếm nhanh...